Error in Regexp: matches does not match?

Hello DXL developer,

this regexp does not match in DOORS 9.1, but in DOORS 7.1
Where is my thinking-error?
 

string strToken = "(^2$|^2.)"
string strText = "2"
 
if (matches(strToken, strText)) {
    print "match \n"
}
else {
        print "no match \n"
}

thsturm - Tue Apr 27 07:56:44 EDT 2010

Re: Error in Regexp: matches does not match?
Mathias Mamsch - Tue Apr 27 09:41:43 EDT 2010

The regexp function was replaced in DOORS 9. I think you can find some info in the DOORS help. Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant Requirement Engineering and DOORS

Re: Error in Regexp: matches does not match?
SystemAdmin - Tue Apr 27 12:10:55 EDT 2010

Mathias Mamsch - Tue Apr 27 09:41:43 EDT 2010
The regexp function was replaced in DOORS 9. I think you can find some info in the DOORS help. Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant Requirement Engineering and DOORS

Mathias is correct, as usual :), that regex changed in 9-point-something. But the answer to your question really depends on what you're looking for with the regex. Any string that starts with "2"?

Re: Error in Regexp: matches does not match?
llandale - Tue Apr 27 17:11:49 EDT 2010

Don't know where I saw it, but v9.0 (or 9.1) had disclaimers about the change in Regular Expressions, part of IBM's 'blue washing' of the Telelogic tools.

In v8, your expression seems to match any string that starts with '2', doesn't not match any other string. In v9, it seems to match any string that starts with "2$", not matching any other string (including "2.")

I've always had problems with them. In your case, what are you asking? It looks like "any string that's not exactly "2$" or any string that's not exactly one or more "2"s; which is any string.

What are you trying to do?

  • Louie

Re: Error in Regexp: matches does not match?
thsturm - Wed Apr 28 06:58:00 EDT 2010

I have done some tests:

(^x$)|(^y.)

works. Also

^(x|y.)$

works.
For me it seems, that it is not possible to have a line end in an alternative: '$|',

Does anybody know, which regexp code is used in DXL?

Re: Error in Regexp: matches does not match?
SystemAdmin - Thu May 06 11:34:29 EDT 2010

thsturm - Wed Apr 28 06:58:00 EDT 2010

I have done some tests:

(^x$)|(^y.)

works. Also

^(x|y.)$

works.
For me it seems, that it is not possible to have a line end in an alternative: '$|',

Does anybody know, which regexp code is used in DXL?

Wrote this to experiment with regex. Use and abuse as you see fit.

DBE rgx = null
DBE str = null
DBE rst = null
 
void doit (DB calledfrom)
{
    string r = get (rgx)
        string s = get (str)
        Regexp x = regexp2 r
        if (x s) set (rst, s[match 0])
        else set (rst, "no match...")
        return
}
 
DB db = centered "Regex Experiment"
rgx = field (db, "Regex:", "", 60, false)
str = field (db, "String:", "", 60, false)
rst = field (db, "Matches:", "", 60, true)
apply (db, "   Go   ", doit)
show db


Again, it's kind of hard, just looking at your code examples, to decipher what you want the regex to do... One problem I'm having interpreting your examples is that the caret (^) and dollar ($) characters mean different things depending on how they're used. The caret means "start of string" normally, but in range brackets it negates. The dollar means "end of string" normally. But it also has another use, which escapes me presently.

Re: Error in Regexp: matches does not match?
llandale - Thu May 06 16:14:27 EDT 2010

SystemAdmin - Thu May 06 11:34:29 EDT 2010

Wrote this to experiment with regex. Use and abuse as you see fit.

DBE rgx = null
DBE str = null
DBE rst = null
 
void doit (DB calledfrom)
{
    string r = get (rgx)
        string s = get (str)
        Regexp x = regexp2 r
        if (x s) set (rst, s[match 0])
        else set (rst, "no match...")
        return
}
 
DB db = centered "Regex Experiment"
rgx = field (db, "Regex:", "", 60, false)
str = field (db, "String:", "", 60, false)
rst = field (db, "Matches:", "", 60, true)
apply (db, "   Go   ", doit)
show db


Again, it's kind of hard, just looking at your code examples, to decipher what you want the regex to do... One problem I'm having interpreting your examples is that the caret (^) and dollar ($) characters mean different things depending on how they're used. The caret means "start of string" normally, but in range brackets it negates. The dollar means "end of string" normally. But it also has another use, which escapes me presently.

Add a field 'Matches1' that uses the lagacy 'regexp' function (instead of regexp2); so perhaps someone can see a difference.

Re: Error in Regexp: matches does not match?
SystemAdmin - Mon May 17 10:03:43 EDT 2010

llandale - Thu May 06 16:14:27 EDT 2010
Add a field 'Matches1' that uses the lagacy 'regexp' function (instead of regexp2); so perhaps someone can see a difference.

DBE rgx = null
DBE str = null
DBE rst1 = null
DBE rst2 = null
 
void doit (DB calledfrom)
{
    string r = get (rgx)
        string s = get (str)
        Regexp x1 = regexp r
        Regexp x2 = regexp2 r
        if (x1 s) set (rst1, s[match 0])
        else set (rst1, "no match...")
        if (x2 s) set (rst2, s[match 0])
        else set (rst2, "no match...")
        return
}
 
DB db = centered "Regex Experiment"
rgx = field (db, "Regex:", "", 60, false)
str = field (db, "String:", "", 60, false)
rst1 = field (db, "Matches1:", "", 60, true)
rst2 = field (db, "Matches2:", "", 60, true)
apply (db, "   Go   ", doit)
show db

Re: Error in Regexp: matches does not match?
Bosch - Tue Jul 05 08:20:50 EDT 2011

SystemAdmin - Mon May 17 10:03:43 EDT 2010

DBE rgx = null
DBE str = null
DBE rst1 = null
DBE rst2 = null
 
void doit (DB calledfrom)
{
    string r = get (rgx)
        string s = get (str)
        Regexp x1 = regexp r
        Regexp x2 = regexp2 r
        if (x1 s) set (rst1, s[match 0])
        else set (rst1, "no match...")
        if (x2 s) set (rst2, s[match 0])
        else set (rst2, "no match...")
        return
}
 
DB db = centered "Regex Experiment"
rgx = field (db, "Regex:", "", 60, false)
str = field (db, "String:", "", 60, false)
rst1 = field (db, "Matches1:", "", 60, true)
rst2 = field (db, "Matches2:", "", 60, true)
apply (db, "   Go   ", doit)
show db

hi,

I have a string by name "Test"
i have a list of groups like
1. AI_Hello-Test_PMs
2. AI_Hello-Test-2.5_PMs
3. AI_Hello-Test-2_PMs

so what i am trying to do is
for g_All in groupList do
{
s1 = g_All.name
s_ProjectName = "Test"
Regexp r = regexp s_ProjectName
if(r s1)
{
print "...."s1
}
}
the output is
.... AI_Hello-Test_PMs
....AI_Hello-Test-2.5_PMs
....AI_Hello-Test-2_PMs

in the above code it is displaying all the groups which all are containg the string "Test", but what i want is it should display only the group which has the text "Test" like only the group "AI_Hello-Test_PMs".

Please help me in this.

Kindly let me know if this possible.

Thank you!

Regards,
Shruthi

Re: Error in Regexp: matches does not match?
llandale - Tue Jul 05 15:26:00 EDT 2011

Bosch - Tue Jul 05 08:20:50 EDT 2011
hi,

I have a string by name "Test"
i have a list of groups like
1. AI_Hello-Test_PMs
2. AI_Hello-Test-2.5_PMs
3. AI_Hello-Test-2_PMs

so what i am trying to do is
for g_All in groupList do
{
s1 = g_All.name
s_ProjectName = "Test"
Regexp r = regexp s_ProjectName
if(r s1)
{
print "...."s1
}
}
the output is
.... AI_Hello-Test_PMs
....AI_Hello-Test-2.5_PMs
....AI_Hello-Test-2_PMs

in the above code it is displaying all the groups which all are containg the string "Test", but what i want is it should display only the group which has the text "Test" like only the group "AI_Hello-Test_PMs".

Please help me in this.

Kindly let me know if this possible.

Thank you!

Regards,
Shruthi

Seems like you want a regexp that looks like "-Test_" and not just "Test".

Be sure to move your regexp OUTSIDE the loop. The "regexp" command is particularly inefficient.

s_ProjectName = "Test"
Regexp r = regexp("-" s_ProjectName "_")
for g_All in groupList do
{ ...

New code should use "regexp2" instead of "regexp", for reason's I don't know.

  • Louie